var app = getApp(),

  $ = require("../../utils/httpHelper.js")
var wxParse = require("../../wxParse/wxParse.js")
Page({
  data: {
    classinfo: {},
    classid:'',
    userInfo: {},
    size:['1','2','3','4','5'],
    showdialog: false,
    pay_type:'',
    isfav:false,
    imglist:[],
    type_id:''
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  onLoad: function (options) {
    if (!app.check_empty(options.id)) {
      $.httpPost("class_detail", { class_id: options.id, rd_session: app.globalData.userInfo.rd_session,}, (data, err) => {
        let arr = []
        let a = data.data.data.thumb
        let b = data.data.data.thumb1
        let c = data.data.data.thumb2
        arr.push(a)
        arr.push(b)
        arr.push(c)
        this.setData({
          classinfo:data.data.data,
          classid: options.id,
          isfav: data.data.data.is_favorite,
          imglist:arr,
          type_id: data.data.data.type_id
        })
        if (data.data.data.content){
          wxParse.wxParse("about", "html", data.data.data.content, this)
        }
        
      })
    }
    
  },
  imageLoad: function (e) {
    var _this = this;
    var $width = e.detail.width,    //获取图片真实宽度  
      $height = e.detail.height,
      ratio = $width / $height;   //图片的真实宽高比例  
    var viewWidth = this.data.width + 20,           //设置图片显示宽度，  
      viewHeight = this.data.width / ratio;    //计算的高度值     
    this.setData({
      imgwidth: viewWidth,
      imgheight: viewHeight
    })
  },
  tophone(){
    var that = this;
    wx.makePhoneCall({
      phoneNumber: this.data.classinfo.phone
    })
  },
  tophone1() {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: this.data.classinfo.phone1
    })
  },
  baoming(){
    if (this.data.classinfo.type_id == '4'){
      $.httpPost("check_classa", { class_id: this.data.classid, rd_session: app.globalData.userInfo.rd_session, }, (data, err) => {
        if(data.data.can_join){
          wx.navigateTo({
            url: '/pages/kecheng/info2?classid=' + this.data.classid + '&orderno=' + data.data.order_no,
          })
        }else{
          wx.showToast({
            title: data.message,
          })
        }
      })
    }else{
      wx.navigateTo({
        url: '/pages/kecheng/info?classid=' + this.data.classid,
      })
    }
    
    
  },
  favorite() {
    if (this.data.isfav) {
      var rd_session = wx.getStorageSync('rd_session');
      $.httpPost("delete_favorite_good", { good_id: this.data.classid, rd_session: rd_session }, (data, err) => {
        this.setData({
          isfav: data.favorite
        })
      })
    } else {
      var rd_session = wx.getStorageSync('rd_session');
      $.httpPost("add_favorite_good", { good_id: this.data.classid, rd_session: rd_session, types: 2 }, (data, err) => {
        this.setData({
          isfav: data.favorite
        })
      })
    }

  }
});